package com.infra.micro.oss.controller;

import com.infra.micro.oss.domain.service.DownloadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RequestMapping("/api/oss/file/download")
@RestController
@Api(tags = {"文件下载服务"})
public class DownloadController {
    @Resource
    private DownloadService downloadService;

    @ApiImplicitParam(name = "bizId", value = "业务文件ID", dataType = "Long", dataTypeClass = Long.class, paramType = "path", required = true)
    @ApiOperation(value = "根据业务文件ID下载文件", notes = "根据业务文件ID下载文件", produces = "application/json")
    @GetMapping("/bizInfo/{bizId}")
    public void downloadByBizId(@PathVariable("bizId") Long bizId, HttpServletResponse response) throws Exception {
        downloadService.downloadByBizId(bizId, response);
    }

    @ApiImplicitParam(name = "fileId", value = "系统文件ID", dataType = "Long", dataTypeClass = Long.class, paramType = "path", required = true)
    @ApiOperation(value = "根据系统文件ID下载文件", notes = "根据系统文件ID下载文件", produces = "application/json")
    @GetMapping("/fileInfo/{fileId}")
    public void downloadByFileId(@PathVariable("fileId") Long fileId, HttpServletResponse response) throws Exception {
        downloadService.downloadByFileId(fileId, response);
    }

    @ApiImplicitParam(name = "bizIds", value = "业务文件ID列表", dataType = "Long", dataTypeClass = Long.class, allowMultiple = true, paramType = "body", required = true)
    @ApiOperation(value = "业务文件ID列表下载文件(Zip)", notes = "业务文件ID列表下载文件(Zip)", produces = "application/json")
    @PostMapping("/bizInfos")
    public void downloadByBizIds(@RequestBody List<Long> bizIds, HttpServletResponse response) throws Exception {
        downloadService.downloadByBizIds(bizIds, response);
    }

    @ApiImplicitParam(name = "fileIds", value = "系统文件ID列表", dataType = "Long", dataTypeClass = Long.class, allowMultiple = true, paramType = "body", required = true)
    @ApiOperation(value = "系统文件ID列表下载文件(Zip)", notes = "系统文件ID列表下载文件(Zip)", produces = "application/json")
    @PostMapping("/fileInfos")
    public void downloadByFileIds(@RequestBody List<Long> fileIds, HttpServletResponse response) throws Exception {
        downloadService.downloadByFileIds(fileIds, response);
    }
}
